<template>
    <div class="body-login">
        <el-form :model="loginForm" class="login-container">
            <h1>欢迎登录</h1>
            <el-form-item>
                <el-input type="input" v-model="loginForm.username" placeholder="请输入账号"></el-input>
            </el-form-item>
            <el-form-item>
                <el-input type="password" v-model="loginForm.password" placeholder="请输入密码"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="handleLogin">登录</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>

<script setup lang="js">
import { reactive, getCurrentInstance } from 'vue';
import { useAllDataStore } from '@/store'
import { useRouter } from 'vue-router';
const loginForm = reactive({
    username: '',
    password: ''
})
const { proxy } = getCurrentInstance()
const store = useAllDataStore()
const router = useRouter()
const handleLogin = async () => {
    //根据登录用户信息请求本地菜单
    const res = await proxy.$api.getMenu(loginForm)
    //拿到菜单以后 要在哪里显示
    store.updateMenuList(res.menuList)
    store.state.token = res.token
    store.addMenu(router)//设置动态路由，这句一定要先于下面这句router.push('/home')，即得有路由才能跳转
    router.push('/home')
}
</script>

<style scoped lang="less">
.body-login {
    width: 100%;
    height: 100%;
    background-image: url("../assets/images/background.png");
    background-size: 100%;
    overflow: hidden;
}

.login-container {
    width: 400px;
    background-color: #fff;
    border: 1px solid #eaeaea;
    border-radius: 10px;
    padding: 35px 35px 15px 35px;
    margin: 250px auto;

    h1 {
        text-align: center;
        margin-bottom: 20px;
        color: #505450;
    }

    //样式刺穿
    :deep(.el-form-item__content) {
        justify-content: center;
    }
}
</style>
